<!DOCTYPE HTML>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="__UI__/css/bs3/dpl.css" rel="stylesheet">
<link href="__UI__/css/bs3/bui.css" rel="stylesheet">
<link href="__UI__/css/page.css" rel="stylesheet" type="text/css" />
</head>
<body> 
<div class="container">
	<div class="search-grid-container">
		<div id="grid"></div>
        <div id="bar"></div>
	</div>
</div>
<script type="text/javascript" src="__UI__/js/jquery-1.8.1.min.js"></script>
<script type="text/javascript" src="__UI__/js/bui.js"></script>
<script type="text/javascript" src="__UI__/js/config.js"></script>
<script type="text/javascript">
	BUI.use('common/page');
	BUI.use(['common/search','bui/overlay'],function (Search,Overlay){
		var columns = [
			{title:'管辖单位',dataIndex:'company',width:100},
			{title:'操作',dataIndex:'',width:100,renderer:function(value,obj){
				var recordStr = Search.createLink({
					id:'records' + obj.id,
					title:'演练记录',
					text:'演练记录',
					href:'{:U("Home/Records/index/id/' + obj.id + '")}',
					isClose:true,
				});
				Search.createLink;
				return recordStr;
			}},
		],
		store = Search.createStore('{:U("Manage/index")}',{
			proxy:{
				save:{removeUrl:'{:U("Manage/index")}'}
			},
			autoSync:true,
			pageSize:10,
			
		}),
		gridCfg = Search.createGridCfg(columns,{
			forceFit:true,
			tbar:{
				items:[
					{text : '<i class="icon-refresh"></i>刷新页面',btnCls : 'button button-small',handler:function(){
						window.location.reload();
					}},
				]
			},
			plugins:[BUI.Grid.Plugins.CheckSelection,BUI.Grid.Plugins.RowNumber] 
		});
		var search = new Search({
			store:store,
			gridCfg:gridCfg,
		}),
		grid = search.get('grid');
		function delFunction(){
			var selections = grid.getSelection();
			delItems(selections);
		}
		function delItems(items){
			var ids = [];
			BUI.each(items,function(item){
				ids.push(item.id);
			});
			if(ids.length){
				BUI.Message.Confirm('确认要删除选中的记录么？',function(){
					$.ajax({
						url:'{:U("Record/del")}',
						dataType:'json',
						data:{ids : ids},
						success:function(data){
							if(data.status == 'y'){
								search.load();
							}else{
								BUI.Message.Alert('删除失败！');
							}
						}
					});
				},'question');
			}
		}
		grid.on('cellclick',function(ev){
			var sender = $(ev.domTarget);
			if(sender.hasClass('btn-del')){
				var record = ev.record;
				delItems([record]);
			}
		});
	});
	$(function(){
	//上移
	var $up = $(".up")
    $up.click(function() {
        var $tr = $(this).parents("tr");
        if ($tr.index() != 0) {
			$tr.fadeOut().fadeIn();
			$tr.prev().before($tr);
			
        }
    });
    //下移
    var $down = $(".down");
    var len = $down.length;
    $down.click(function() {
        var $tr = $(this).parents("tr");
        if ($tr.index() != len - 1) {
			$tr.fadeOut().fadeIn();
            $tr.next().after($tr);
        }
    });
	//置顶
	var $top = $(".top");
	$top.click(function(){
		var $tr = $(this).parents("tr");
		$tr.fadeOut().fadeIn();
		$(".bui-grid-table").prepend($tr);
		$tr.css("color","#f60");
	});
});
</script>
</body>
</html>